package com.wanli.agent.homepage;

import android.os.Bundle;
import android.widget.TextView;

import com.wanli.agent.R;
import com.wanli.agent.base.BaseActivity;
import com.wanli.agent.bean.WithdrawListBean;
import com.wanli.agent.event.WithdrawDataEvent;
import com.wanli.agent.utils.DateTimeUtil;
import com.wanli.agent.utils.NumberFormatUtils;
import com.wanli.agent.widget.AppTitleBar;

import org.greenrobot.eventbus.EventBus;

import java.util.Date;

import butterknife.BindView;
import butterknife.ButterKnife;

public class WithdrawDetailsActivity extends BaseActivity {

    @BindView(R.id.title_bar)
    AppTitleBar titleBar;
    @BindView(R.id.tv_id)
    TextView tvId;
    @BindView(R.id.tv_agent)
    TextView tvAgent;
    @BindView(R.id.tv_status)
    TextView tvStatus;
    @BindView(R.id.tv_money)
    TextView tvMoney;
    @BindView(R.id.tv_time)
    TextView tvTime;
    @BindView(R.id.tv_remark)
    TextView tvRemark;
    private WithdrawListBean.DataBean.ItemListBean dataBean;
    private WithdrawDataEvent dataEvent;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_withdraw_details);
        ButterKnife.bind(this);
        initView();
    }

    public void initView() {
        dataEvent = EventBus.getDefault().getStickyEvent(WithdrawDataEvent.class);
        if (dataEvent != null) {
            EventBus.getDefault().removeStickyEvent(dataEvent);
            dataBean = dataEvent.getDataBean();
        }
        if (dataBean != null) {
            tvId.setText(dataBean.getId() + "");
            tvAgent.setText(dataBean.getAgent_name());
            //0-服务商已申请,1-财务已初审,2-财务转账中,3-服务商已撤销,4-财务已拒绝,9-转账成功10-转账失败
            if (dataBean.getStatus() == 0) {
                tvStatus.setText("服务商已申请");
            } else if (dataBean.getStatus() == 1) {
                tvStatus.setText("财务已初审");
            } else if (dataBean.getStatus() == 2) {
                tvStatus.setText("财务转账中");
            } else if (dataBean.getStatus() == 3) {
                tvStatus.setText("服务商已撤销");
            } else if (dataBean.getStatus() == 4) {
                tvStatus.setText("财务已拒绝");
            } else if (dataBean.getStatus() == 9) {
                tvStatus.setText("转账成功");
            } else {
                tvStatus.setText("申请成功");
            }
            String money = NumberFormatUtils.formatTwoDecimal(Double.parseDouble(dataBean.getMoney()) / 100);
            tvMoney.setText(money + "元");
            tvTime.setText(DateTimeUtil.format7(new Date(Long.parseLong(dataBean.getUpdate_time()) * 1000)));
            tvRemark.setText(dataBean.getRemark());
        }
    }
}
